home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
weyl
/
weyl_lsp.lha
/
poly-tools.lisp
< prev
next >
Wrap
Lisp/Scheme
|
1991-10-04
|
5KB
|
139 lines
;;; -*- Mode:Lisp; Package:Weyli; Base:10; Lowercase:T; Syntax:Common-Lisp -*-
;;; ===========================================================================
;;; Polynomial Domain Tools
;;; ===========================================================================
;;; (c) Copyright 1989, 1991 Cornell University
;;; $Id: poly-tools.lisp,v 2.13 1991/10/04 22:43:43 rz Exp $
(in-package "WEYLI")
(defmethod print-object ((d polynomial-ring) stream)
(with-slots (coefficient-domain) d
(format stream "~A[" coefficient-domain)
(display-list (ring-variables d) stream)
(princ "]" stream)))
(defmethod initialize-instance :after
((domain variable-hash-table) &rest plist)
(declare (ignore plist))
(with-slots (variable-hash-table variable-table variables) domain
(setq variable-hash-table (make-hash-table :test #'equal))
(setq variable-table (make-array (list (max (length variables) 1) 2)))
(loop for var in variables
with i = 0
do (setf (gethash var variable-hash-table) i)
(setf (aref variable-table i 0) var)
(incf i))))
(defmethod variable-index ((domain variable-hash-table)
(variable (or symbol list)))
(gethash (coerce variable *general*) (variable-hash-table domain)))
(defmethod variable-symbol ((domain variable-hash-table) (order-number number))
(aref (variable-index-table domain) order-number 0))
;;(defmethod variable-symbol ((domain variable-hash-table) (poly polynomial))
;; (aref (variable-index-table domain) (poly-order-number (poly-form poly)) 0))
(defmethod get-variable-number-property
((domain variable-hash-table) order-number property)
(getf (aref (variable-index-table domain) order-number 1) property))
(defmethod set-variable-number-property
((domain variable-hash-table) order-number property value)
(setf (getf (aref (variable-index-table domain) order-number 1) property)
value))
(defsetf get-variable-number-property set-variable-number-property)
(defmethod get-variable-property
((domain variable-hash-table) variable property)
(setq variable (coerce variable *general*))
(get-variable-number-property domain (variable-index domain variable)
property))
(defmethod set-variable-property
((domain variable-hash-table) variable property value)
(setq variable (coerce variable *general*))
(set-variable-number-property domain (variable-index domain variable)
property value))
;; Defined in general, which is loaded first.
;;(defsetf get-variable-property set-variable-property)
(defmethod add-new-variable ((ring variable-hash-table) variable)
(setq variable (coerce variable *general*))
(with-slots (variables variable-hash-table variable-table) ring
(unless (member variable variables :test #'ge-equal)
(let* ((count (length variables))
(array (make-array (list (1+ count) 2))))
(setq variables (append variables (list variable)))
(copy-array-contents variable-table array)
(setq variable-table array)
(setf (aref variable-table count 0) variable)
(setf (gethash variable variable-hash-table) count)
count))))
(defmethod initialize-instance :after ((domain single-variable-hash-table)
&rest plist)
(declare (ignore plist))
(with-slots (variables variable) domain
(setq variables (list variable))))
(defmethod variable-index ((domain single-variable-hash-table)
(variable polynomial))
0)
(defmethod variable-index ((domain single-variable-hash-table)
(variable symbol))
0)
(defmethod variable-symbol ((domain single-variable-hash-table)
(poly polynomial))
(cond ((eql (domain-of poly) domain)
(svht-variable domain))
(t (error "~S is not an element of ~S" poly domain))))
(defmethod variable-symbol ((domain single-variable-hash-table)
(poly number))
(cond ((lisp:zerop poly)
(svht-variable domain))
(t (error "~D is not an index for an element of ~S" poly domain))))
(defmethod get-variable-number-property
((domain single-variable-hash-table) order-number property)
(if (lisp:zerop order-number)
(getf (svht-variable-plist domain) property)
(error "Not the index of a variable")))
(defmethod set-variable-number-property
((domain single-variable-hash-table) order-number property value)
(if (lisp:zerop order-number)
(setf (getf (svht-variable-plist domain) property)
value)
(error "Not the index of a variable")))
(defmethod get-variable-property ((domain single-variable-hash-table) variable property)
(if (eql variable (svht-variable domain))
(getf (svht-variable-plist domain) property)
(error "~S is not a variable of ~S" variable domain)))
(defmethod set-variable-property ((domain single-variable-hash-table) variable property value)
(if (eql variable (svht-variable domain))
(setf (getf (svht-variable-plist domain) property) value)
(error "~S is not a variable of ~S" variable domain)))
(defmethod add-new-variable ((ring single-variable-hash-table) variable)
(declare (ignore variable))
(error "Can't add a variable to univariate polynomial domain (FIXTHIS)"))
(defmethod zero ((domain caching-zero-and-one))
(with-slots (zero) domain
zero))
(defmethod one ((domain caching-zero-and-one))
(with-slots (one) domain
one))